define(["cmn","bde"],function(cmn,bde){
	var ejs=cmn.ejs("19911204/2/blogAdd"),eid=700,_eid=700;
	ejs.set("main","main");
	ejs.set("result","result");
	return {
		init:function(){
			var _=this;
			_.renderMain();
		},
		renderMain:function(){
			var _=this;
			_.el.html(ejs.main,{eid:_eid},function(){
				bde.getEditor(_eid+"",{
    			 	zIndex : 6,
    			 	autoClearinitialContent:true,
    			 	autoHeightEnabled:false,
    			 	autoFloatEnabled:false,
    			 	toolbar:[
				            'source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
				            'insertorderedlist insertunorderedlist |  cleardoc paragraph | fontfamily fontsize' ,
				            '| justifyleft justifycenter justifyright justifyjustify |',
				            'link unlink | emotion | map',
				            '| horizontal print preview ', 'drafts', 'formula','warp code label'
				    ]
    			});
				eid=_eid++;
				_.el.find("#publish1015").on("click",function(){
					if(!_.el.validate()){
						cmn.alert("验证错误，请根据输入框提示填写");
						return;
					}
					if(!bde.getEditor(eid+"").hasContents()){
						cmn.alert("内容不能为空");
						return;
					}
					_.save();
				});
				
			});
		},
		save:function(){
			var _=this,title=_.el.find("#title1015").val();
			cmn.lbox.show();
			cmn.post({
				action:"Blog_save",
				params:{
					title:_.el.find("#title1015").val(),
					tag:_.el.find("#tag1015").val(),
					content:bde.getEditor(eid+"").getContent()
				}
			}).then(function(data){
				cmn.lbox.hide();
				_.renderResult(data,title);
			});
		},
		renderResult:function(id,title){
			var _=this;
			_.el.html(ejs.result,{id:id,title:title},function(){
				_.el.find("#return1017").on("click",function(){
					_.renderMain();
				});
			});

		}
	}
});